package com.hex.liyue.usermodule.view;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.hex.liyue.R;
import com.hex.liyue.commonmodule.utils.L;
import com.hex.liyue.commonmodule.utils.ScreenUtils;

/**
 * 这是一个性别筛选的弹框
 *
 */
public class PopSex extends PopupWindow implements View.OnClickListener {
    private final Context context;
    private TextView tv_my_edit_woman, tv_my_edit_man, tv_my_edit_cancel;
    private OnBtnClickListener onBtnClickListener;

    public interface OnBtnClickListener {
        void onBtnWoManClickListener();

        void onBtnManClickListener();

    }

    public void setOnBtnClickListener(OnBtnClickListener onBtnClickListener) {
        this.onBtnClickListener = onBtnClickListener;
    }

    public PopSex(Context context) {
        this.context = context;
        View view = View.inflate(context, R.layout.pop_sex, null);
        setWidth(ScreenUtils.getScreenWidth(context));
        setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        setContentView(view);
        setFocusable(true);//设置获取焦点
        setTouchable(true);//设置可以触摸
        setOutsideTouchable(true);//设置外边可以点击
        setBackgroundDrawable(new BitmapDrawable());
        //设置点击事件的监听
        setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                    //不在该界面的点击事件
                    dismiss();
                    return true;
                }
                return false;
            }
        });
        initView(view);
        initListener();
    }

    private void initView(View view) {
        tv_my_edit_woman = (TextView) view.findViewById(R.id.tv_my_edit_woman);
        tv_my_edit_man = (TextView) view.findViewById(R.id.tv_my_edit_man);
        tv_my_edit_cancel = (TextView) view.findViewById(R.id.tv_my_edit_cancel);
    }

    private void initListener() {
        tv_my_edit_woman.setOnClickListener(this);
        tv_my_edit_man.setOnClickListener(this);
        tv_my_edit_cancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_my_edit_woman:
                L.d("woman", "点击了女");
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnWoManClickListener();
                }
                dismiss();
                break;
            case R.id.tv_my_edit_man:
                L.d("man", "点击了男");
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnManClickListener();
                }
                dismiss();
                break;
            case R.id.tv_my_edit_cancel:
                L.d("cancel", "点击了取消");
                dismiss();
                break;

        }
    }
}
